<?php
namespace App\Library\System\Model;

use App\Library\System\Model;
use Zend\Db\Sql\Where;

/**
 * Search Model
 *
 * @category   Model
 * @package    App\Library\System\Model
 * @author     Loi Nguyen <loint@peslook.com>
 * @copyright  Peslook
 * @version    1.0
 * @since      Class available since Release 1.0
 */
class SearchModel extends Model
{

    /**
     * Keyword
     *
     * @var null | string
     */
    public $keyword;

    /**
     * Constructor
     *
     * @param null $keyword
     */
    public function __construct($keyword = null)
    {
        parent::__construct();
        $this->keyword = $keyword;
    }

    /**
     * Change search keyword
     *
     * @param $keyword
     */
    public function changeKeyword($keyword)
    {
        $this->keyword = $keyword;
    }

    /**
     * Get suggest user
     * Suggest the username based on keyword
     *
     * @return array|\ArrayObject|null|\Zend\Db\ResultSet\ResultSet
     */
    public function getSuggestUser()
    {
        return $this->more($this->select()
                ->columns(array(
                    'id',
                    'name'  => 'name',
                    'info'  => 'headline',
                    'image' => 'avatar',
                    'alias' => 'alias'
                ))
                ->from('user')
                ->where(
                    $this->where()->like('name', '%' . $this->keyword . '%')
                )
        );
    }

    /**
     * Get suggest skill
     *
     */
    public function getSuggestSkill()
    {
        return $this->more($this->select()
                ->columns(array(
                    'id',
                    'name'  => 'skillname',
                    'info'  => 'description',
                    'image' => 'image',
                    'alias' => 'alias'
                ))
                ->from('skill')
                ->where($this->where()->like('skillname', '%' . $this->keyword . '%'))
        );
    }

    /**
     * Get suggest organization
     */
    public function getSuggestOrganization()
    {
        // TODO
    }


} 